# AUTHOR: DING
# -*- codeing = utf-8 -*-
# @Time: 2024/2/20 9:52
# @Author: 86139
# @Site: 
# @File: 09-dataloader.py
# @Software: PyCharm
# tensorboard --logdir=pytorch/logs --port=6007

import torchvision
from torch.utils.data import DataLoader

# 测试集
from torch.utils.tensorboard import SummaryWriter

test_data = torchvision.datasets.CIFAR10(root="./dataset", train=False, transform=torchvision.transforms.ToTensor(),
                                         download=True)
# loader将每4份数据打包（聚合），数据是随机取的 sampler= 控制
test_loader = DataLoader(dataset=test_data, batch_size=4, shuffle=True, num_workers=0,
                         drop_last=False)  # shuffle:多次load是否打乱洗牌

# 测试集的第一张图片
img, target = test_data[0]
print(img.shape)
print(target)

writer = SummaryWriter("./logs")
step = 0
for data in test_loader:
    imgs, targets = data
    # print(imgs.shape)
    # print(targets)
    writer.add_images("test_data", imgs, step)
    step += 1

writer.close()
